package Operation;

import Dao.DataOperation;
import JavaBeans.Book;

import java.util.Scanner;

/**
 * 新增图书记录功能类
 */
public class AppendOperation implements IOperation{

    @Override
    public void operate() {
        System.out.println("新增图书...");
        //获取图书信息
        Scanner in = new Scanner(System.in);
        System.out.print("书名：");
        String name = in.nextLine();
        System.out.print("作者：");
        String author = in.nextLine();
        System.out.print("价格：");
        double price = in.nextDouble();
        in.nextLine(); //过滤多余换行符
        System.out.print("类型：");
        String category = in.nextLine();

        //往book_list表中插入一条图书记录
        String sql = "insert into book_list(name,author,price,category) values(?,?,?,?)";
        boolean isUpdated = DataOperation.update(sql, name, author, price, category);
        if (isUpdated){
            System.out.println("已新增一条图书信息。");
        }else{
            System.out.println("新增失败！");
        }
    }
}
